#!/usr/bin/env python

import subprocess

def test_update():
    result = subprocess.run(['apt', 'update'], capture_output=True, text=True)
    assert result.returncode == 0
    assert "Get:1" in result.stdout  # Check if update was successful

def test_install():
    result = subprocess.run(['apt', 'install', 'nginx', '-y'], capture_output=True, text=True)
    assert result.returncode == 0
    assert "Setting up nginx" in result.stdout  # Check if installation was successful

def test_remove():
    result = subprocess.run(['apt', 'remove', 'nginx', '-y'], capture_output=True, text=True)
    assert result.returncode == 0
    assert "Removing nginx" in result.stdout  # Check if removal was successful

def test_search():
    result = subprocess.run(['apt', 'search', 'python'], capture_output=True, text=True)
    assert result.returncode == 0
    assert "python" in result.stdout  # Check if search returned results

def test_upgrade():
    result = subprocess.run(['apt', 'upgrade', '-y'], capture_output=True, text=True)
    assert result.returncode == 0
    assert "upgraded" in result.stdout  # Check if upgrade was successful

# Run the tests
if __name__ == '__main__':
    import pytest
    pytest.main()